#!/usr/bin/perl

use strict;
use LWP::UserAgent;
use HTTP::Request;

my $uri = 'https://kaolabo.com/api/detect?apikey=5ac9d12d9c981b84ce777d28621aa58d';
#$uri .= '&url=http://yaplog.jp/cv/strawberry2/img/19971/img20080210_t.jpg'; 

$uri .= '&url=http://yaplog.jp/cv/strawberry2/img/19951/img20080210_t.jpg';

my $request_content;

my $request = HTTP::Request->new( 'GET' => $uri);

$request->content($request_content)
  if( $request_content );

my $ua = LWP::UserAgent->new;

#    $ua->timeout(10);
#    $ua->proxy(['http','ftp'], 'http://proxy.internal:8080/');
#if( $PROXY ){
#    $ua->timeout($PROXY_TIMEOUT);
#    $ua->proxy(['http','ftp'], $PROXY );
#}

my $response = $ua->request($request);
if ( $response->is_success ) {
    $response;
}else{
    warn $response->status_line,"\n";
    $response;
}

#　　　　　　　　<left-eye x="336" y="153" />
#　　　　　　　　<right-eye x="318" y="153" />
#
#　　　　　　　　<left-eye x="336" y="153" />
#　　　　　　　　<right-eye x="318" y="153" />

my $content =  $response->content;
print "$content \n\n";
while( $content =~ s/<face(.+?)<\/face// ){
    my $node = $1;
print "> $node \n";
      if( $node =~ /left\-eye\ x\=\"(\d+)\"\ y\=\"(\d+)\"/i ){
print "left > x:$1 y:$2\n" 
      }

      if( $node =~ /right\-eye\ x\=\"(\d+)\"\ y\=\"(\d+)\"/i ){
print "right > x:$1 y:$2\n" 
      }
}
